<?php
	// Liên kết - Phần xử lý
	class lienketdb
	{
	 	public function Them($TenLienKet = '', $DiaChi = '')
		{
			$sql = "insert into lienket (TenLienKet, DiaChi) 
					values(".dataservice::QuoteSmart($TenLienKet).", 
						   ".dataservice::QuoteSmart($DiaChi).")";
			$db = new dataservice();
			$ret = $db->ExecuteNonQuery($sql);
			return $ret;
		}
		
		public function CapNhat($MaLienKet = 0, $TenLienKet = '', $DiaChi = '')
		{
			$sql = "update lienket 
					set TenLienKet = ".dataservice::QuoteSmart($TenLienKet).", 
						DiaChi = ".dataservice::QuoteSmart($DiaChi)." 
					where MaLienKet = ".dataservice::QuoteSmart($MaLienKet);
			
			$db = new dataservice();
			$ret = $db->ExecuteNonQuery($sql);
			return $ret;
		}
		
	  	public function LayDanhSach($MaLienKet = 0,
	  								$TenLienKet = "",
	  								$DiaChi = "")
		{
			$sql = "select * from lienket where (1)";
			
			if($MaLienKet > 0)
				$sql .= " AND MaLienKet = $MaLienKet";
				
			if($TenLienKet != "")
				$sql .= " AND TenLienKet = '$TenLienKet'";
			
			if($DiaChi != "")
				$sql .= " AND DiaChi = '$DiaChi'";			
			
			$db = new dataservice();
			$ret = $db->ExecuteQuery($sql);
			return $ret;
		}
		
		public function Xoa($MaLienKet = 0)
		{
			$sql = 'delete from lienket where (1)';
			
			if ($MaLienKet > 0)
				$sql .= ' and MaLienKet = '.dataservice::QuoteSmart($MaLienKet);
			
			$db = new dataservice();
			$ret = $db->ExecuteNonQuery($sql);
			return $ret;
		}
		
		public function XoaTatCa()
		{
			$sql = "DELETE FROM lienket";			
			
			$db = new dataservice();
			$ret = $db->ExecuteNonQuery($sql);
			return $ret;
		}
	}
?>
